package org.tity.test.redis;

import java.io.IOException;
import java.util.LinkedHashSet;
import java.util.Set;

import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.JedisCluster;
import redis.clients.jedis.JedisPoolConfig;

public class JedisClusterClient {

	public static void main(String[] args) {
	    JedisPoolConfig poolConfig = new JedisPoolConfig();
 
	    // 最大连接数
	    poolConfig.setMaxTotal(10);
	    // 最大空闲数
	    poolConfig.setMaxIdle(2);
	    // 最大允许等待时间，如果超过这个时间还未获取到连接，则会报JedisException异常：
	    // Could not get a resource from the pool
	    poolConfig.setMaxWaitMillis(1000);
	    Set<HostAndPort> nodes = new LinkedHashSet<HostAndPort>();
	    nodes.add(new HostAndPort("10.88.2.80", 9802));
	    nodes.add(new HostAndPort("10.88.2.80", 9804));
	    nodes.add(new HostAndPort("10.88.2.80", 9806));
//	    
	    nodes.add(new HostAndPort("10.88.2.81", 9801));
	    nodes.add(new HostAndPort("10.88.2.81", 9803));
	    nodes.add(new HostAndPort("10.88.2.81", 9805));
	    
	    JedisCluster cluster = new JedisCluster(nodes, 15000, 15000, 8, "cc3690x@fy", poolConfig);
//	    String name = cluster.get("name");
//	    System.out.println(name);
	    cluster.set("age", "18");
	    
	    for (int i = 0; i < 1000; i++) {
	    	Object value=cluster.get("age");
	    	if(value==null)
	    	{
	    		System.out.println("null");
	    	}
	    	 System.out.println(value);
		}
	    
	  
	    try {
	        cluster.close();
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}
	
}
